import { takeEvery, takeLatest,put } from 'redux-saga/effects'
import request from '@/utils/request'

function * init(){
    console.log('hello saga');
    // 监听SagaAction
    // yield takeEvery('login_async',login)
    // 防抖优化
    yield takeLatest('login_async',login)

}

function * login(action){
    console.log('login--->',action)
    const {data} = yield request.get('/user/login',{
        params:action.payload
    })

    // 触发action2:reducerAction
    yield put({
        type:'login',
        payload:data.data
    })

    action.success(data)
}


export default init;

// action1: sagaAction
// dispatch({type:'login_async'})
//action2:reducerAction
// dispatch({type:'login'})